<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><%
	javax.servlet.http.Cookie c = new javax.servlet.http.Cookie("a", "aaa111");
	System.out.println("ver:" + c.getVersion());
	System.out.println("domain:" + c.getDomain());
	System.out.println("path:" + c.getPath());
	System.out.println("maxAge:" + c.getMaxAge());
	System.out.println("secure:" + c.getSecure());
	
//	c.setSecure(true);
	
	response.addCookie(c);
	
	response.addHeader("Set-Cookie", "b=bbb222; HttpOnly");

	String user = request.getParameter("user");
	if (user != null && !user.equals("")) {
		request.getSession().setAttribute("user", user);
		response.sendRedirect("html5_a.jsp");
	}
%>
<!DOCTYPE HTML>  
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript">
	function $$(id) {
		return document.getElementById(id);
	}
	
	function set(type) {
		var name, value;
		
		if (type == 'session') {
			name = $$('name1').value;
			value =  $$('value1').value;
			sessionStorage.setItem(name, value);
		} else if (type == 'local') {
			name = $$('name2').value;
			value =  $$('value2').value;
			localStorage.setItem(name, value);
		}
	}
	
	function get(type) {
		var name;
		if (type == 'session') {
			name = $$('name1').value;
			alert(sessionStorage.getItem(name));
		} else if (type == 'local') {
			name = $$('name2').value;
			alert(localStorage.getItem(name));
		}		
	}
	
	function getCookie(name) {
		var m = new RegExp(name + '=(.*?)(;|$)').exec(document.cookie);
		return m ? m[1] : null;
	}
	window.onload = function() {
//		$$('jSessionId').innerHTML = getCookie('JSESSIONID');
		$$('jSessionId').innerHTML = document.cookie;
	};

	
	(function() {
		
		// storage
/*		
		sessionStorage.setItem('sname', 'svalue');
		localStorage.setItem('lname', 'lvalue');
		
		sessionStorage.setItem('', null);
		sessionStorage.setItem(null, 'a');
		sessionStorage.setItem('a', undefined);
		
		alert(sessionStorage.getItem('') === 'null');
		alert(sessionStorage.getItem(null) === 'a');
		alert(sessionStorage.getItem('null') === 'a');
		alert(sessionStorage.getItem('a') === 'undefined');
		
		for (var i = 0; i < sessionStorage.length; i++) {
			alert(sessionStorage.key(i));
		}
		
		alert(sessionStorage);
		sessionStorage.removeItem('');
		sessionStorage.clear();
		alert(sessionStorage);
*/

// 		var db = openDatabase('mydb_1000w3', '', '', '');	
// 		db.transaction(function(tx) {
// 			tx.executeSql('drop table if exists emp');
// 			tx.executeSql('create table if not exists emp(id int, name varchar(20))');
// 		});
		
// 		var db2 = openDatabase('mydb_1000w3', '', '', '');	
// 		db2.transaction(function(tx) {
// 			tx.executeSql('drop table if exists emp');
// 			tx.executeSql('create table if not exists emp(id int, name varchar(20))');
// 		});
		
	// 187s	
 	var d1 = new Date, d2, n = 0;

// 		db.transaction(function(tx) {
// 			for (var i = 0; i < 5000000; i++) {
// 				tx.executeSql('insert into emp values(?, ?)', [i, 'meng' + '_' + i]);
// 			}
// 			d2 = new Date;
// 			alert('用时(毫秒):' + (d2.getTime() - d1.getTime()));
// 		});	

	
// 	for (var k = 0; k < 10; k++) {
// 		db.transaction(function(tx) {
// 			for (var i = 0; i < 1000000; i++) {
// 				tx.executeSql('insert into emp values(?, ?)', [i, 'meng' + k + '_' + i]);
// 			}
// 			d2 = new Date;
// 			if (++n == 10)
// 				alert('用时(毫秒):' + (d2.getTime() - d1.getTime()));
// 		});	
// 	}
	
// 	function a() {
// 		db.transaction(function(tx) {
// 			for (var i = 0; i < 1000000; i++) {
// 				tx.executeSql('insert into emp values(?, ?)', [i, 'meng' + i]);
// 			}

// 			if (++n == 10) {
// 				d2 = new Date;
// 				alert('用时(毫秒):' + (d2.getTime() - d1.getTime()));
// 			}
// 			else
// 				a();
// 		});
// 	}
				
	
// 	a();	
		
		
		
		
		
		
		
	})();
	
</script>

</head>
<body>
    name: <input type="text" id="name1"/>
    value: <input type="text" id="value1"/>
    <button onclick="set('session')">session set</button>
    <button onclick="get('session')">session get</button> <br/>
    
    name: <input type="text" id="name2"/>
    value: <input type="text" id="value2"/>
    <button onclick="set('local')">local set</button>
    <button onclick="get('local')">local get</button>
    
    <br/><br/>
    <a href="html5_b.html" target="_self">html5_b (_self)</a>
    <a href="html5_b.html" target="_blank">html5_b (_blank)</a>
    
    <br/><br/>
    cookie: <span id="jSessionId"></span>
    
    <br/><br/>
    <%
    	Object o =  request.getSession().getAttribute("user");
    	if (o != null && !o.toString().equals("")) {
	%>
		<h3>Hello, <%=o.toString()%></h3>
	
    <% } else { %>
    	<form action="">
			user: <input name="user"> <input type="submit" value="登录">   	
    	</form>
    <%	} %>
    
    
    
<!--     <img src="http://localhost:8088/z_mytest/jsp/html5_a.jsp#.gif" width="100" height="100"/> -->
    
    
    
  
    
</body>
</html>